package kk.json.utils;

/**
 * 时间转换
 * 
 * @author idong_xiaohei
 * 
 */
public class TimeUtils {
	/**
	 * int --> 00:00:00
	 * 
	 * @param tempTime
	 * @return
	 */
	public static String second2Time(int tempTime) {
		return second2Time(tempTime, "");
	}

	/**
	 * int --> 00 : 00 : 00
	 * 
	 * @param tempTime
	 * @return
	 */
	public static String second2Time(int tempTime, String blabk) {
		int tempMHout = tempTime / 3600;
		int tempMMinute = tempTime % 3600 / 60;
		int tempMSecond = tempTime % 60;
		StringBuilder timeBuilder = new StringBuilder();
		timeBuilder.append(tempMHout > 9 ? tempMHout : "0" + tempMHout);
		timeBuilder.append(blabk + ":" + blabk);
		timeBuilder.append(tempMMinute > 9 ? tempMMinute : "0" + tempMMinute);
		timeBuilder.append(blabk + ":" + blabk);
		timeBuilder.append(tempMSecond > 9 ? tempMSecond : "0" + tempMSecond);
		return timeBuilder.toString();
		// int sec = (totalSec % 60);// 秒
		// int min = (totalSec / 60);
		// int hour = min / 60;
		// if (min >= 60) min = min % 60;
		// // 时间
		// try {
		// return String.format("%1$02d:%2$02d:%3$02d", hour,min, sec));
		// } catch (Exception e) {
		// return hour + ":" + min + ":" + sec;
		// e.printStackTrace();
		// }
	}

	/**
	 * int --> 0:00'00"
	 * 
	 * @param tempTime
	 * @return
	 */
	public static String second2Pace(int tempTime) {
		int tpHout = tempTime / 3600;
		int tpMinute = tempTime % 3600 / 60;
		int tpSecond = tempTime % 60;
		StringBuilder tpBuilder = new StringBuilder();
		tpBuilder.append(tpHout > 0 ? tpHout + ":" : "");
		if (tpHout > 0) {
			tpBuilder.append(tpMinute > 9 ? tpMinute : "0" + tpMinute);
		} else {
			tpBuilder.append(tpMinute);
		}
		tpBuilder.append("\'");
		tpBuilder.append(tpSecond > 9 ? tpSecond : "0" + tpSecond);
		tpBuilder.append("\"");
		return tpBuilder.toString();
	}

	/**
	 * 算给出时间距离现在时间多久前
	 * 
	 * @param lasttime
	 * @return
	 */
	public static String ago(int lasttime) {
		String ago = "";

		long now = System.currentTimeMillis() / 1000;
		int apart_time = (int) now - lasttime;
		int apart_minute = apart_time / 60;
		int apart_hour = apart_time / 3600;
		int apart_day = apart_time / (3600 * 24);
		if (apart_minute < 60)
			ago = apart_minute + "分钟前";
		else if (apart_minute > 60 && apart_hour < 24)
			ago = apart_hour + "小时前";
		else
			ago = apart_day + "天前";

		return ago;
	}
}
